#ifndef _2048_H
#define _2048_H

#define FOUR 4

enum KEY
{
    UP = 72,
    DOWN = 80,
    LEFT = 75,
    RIGHT = 77,
    ESC = 27
};

int data[FOUR][FOUR];
int temp[FOUR][FOUR];

// 前向声明代替包含
struct interface;
typedef struct interface* face_p;

// LVGL事件和对象前向声明
typedef struct _lv_event_t lv_event_t;
typedef struct _lv_obj_t lv_obj_t;
typedef struct _lv_timer_t lv_timer_t;
typedef struct _lv_font_t lv_font_t;

// 枚举前向声明
typedef enum {
    GAME_RUNNING,
    GAME_OVER,
    GAME_WIN
} game_state_t;

LV_FONT_DECLARE(lv_font_montserrat_24);   // 声明字体是外部定义的

//界面
extern void game_2048(face_p head);// 2048游戏界面

//事件
extern void event_handler(lv_event_t * e);// 检测滑动回调函数

extern int get_config();
extern void set_config(int value);
extern int estimate(int (*data)[FOUR], int (*temp)[FOUR]); // 判断有无元素发生变化
extern int get_arrow_key();                                // 获取键盘上的ASCII码值
extern int write_2048(int (*data)[FOUR]);                       // 随机写入一个2或4到棋盘上的随机位置
extern int left(int (*data)[FOUR], int (*temp)[FOUR]);     // 左移动
extern int right(int (*data)[FOUR], int (*temp)[FOUR]);
extern int down(int (*data)[FOUR], int (*temp)[FOUR]);
extern int up(int (*data)[FOUR], int (*temp)[FOUR]);
extern int estchess(int (*data)[FOUR]);

// 函数声明
void update_game_board(lv_timer_t * timer);
void refresh_game_ui(lv_obj_t * cont_game, int data[FOUR][FOUR]);
// 重置函数
void reset_game(lv_event_t *e);
/**
 * @brief 更新分数显示
 */
void update_score_display(int score);

typedef struct menu
{
    lv_obj_t * obj;
    face_p head;
    int btn_state;
    lv_obj_t * g_cont_game;
    lv_obj_t * g_score_label;
    lv_timer_t * g_game_timer;
    game_state_t *g_game_state;
    int *g_current_score;
    lv_obj_t * game_over_label;
}menu_t,*menu_p;

//菜单按钮事件
void menu_game(lv_event_t *e);
void home_game(lv_event_t *e);

#endif